<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
 * SimplyPost
 *
 * @author		Pascal Kriete
 * @package		SimplyPost
 * @copyright	Copyright (c) 2008, Pascal Kriete
 * @license 	http://www.gnu.org/licenses/lgpl.txt
 */

// ------------------------------------------------------------------------

/**
 * Topic Admin Controller
 *
 * @package		SimplyPost
 * @subpackage	Topic
 * @category	Controller
 * @author		Pascal Kriete
 */

class Admin extends Administrator {

	/**
	 * Controller
	 *
	 * @access	public
	 */	
	function Admin()
	{
		parent::Administrator();
	}
	
	// --------------------------------------------------------------------
	
	/**
	 * Delete a topic and all children
	 *
	 * @access	public
	 * @param	integer	topic id
	 * @param	integer	parent id
	 */
	function delete($id, $forum)
	{
		$this->load->model('Top_model', 'Topic');
		$this->Topic->delete($id);

		$this->session->set_flashdata('msg', 'Topic Deleted!');
		redirect('forum/view/'.$forum);
	}
	
	// --------------------------------------------------------------------
	
	/**
	 * Edit topic title through ajax
	 *
	 * @access	public
	 * @param	integer	topic id
	 */
	function edit_title($id)
	{
		if (!AJAX)
			show_404();
		
		$this->load->model('Top_model', 'Topic');
		$data = $this->Topic->get($id);
	
		$this->load->helper('form');
		$this->load->library('validation');

		$rules['name'] = "trim|required|xss_clean";
		$this->validation->set_rules($rules);

		$fields['name'] = 'Title';
		$this->validation->set_fields($fields);

		$this->validation->set_error_delimiters('<p style="color:#900">', '</p>');
		
		if ($this->validation->run() == FALSE)
		{
			echo 'Invalid Input';
		}
		else
		{
			$this->Topic->update($id, array('name' => $_POST['name']));
			echo $_POST['name'];
		}
	}
}